package org.songwang.org.controller;

import org.songwang.basic.AjaxResult;
import org.songwang.basic.PageList;
import org.songwang.org.domain.Systemdictionarytype;
import org.songwang.org.query.SystemdictionarytypeQuery;
import org.songwang.org.service.ISystemdictionarytypeservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {
    @Autowired
    private ISystemdictionarytypeservice systemdictionarytypeservice;

    @GetMapping
    public List<Systemdictionarytype> findAll() {
        return systemdictionarytypeservice.findAll();
    }

    @GetMapping("/{id}")
    public Systemdictionarytype findById(@PathVariable("id") Long id) {
        return systemdictionarytypeservice.findById(id);
    }

    @PutMapping
    public AjaxResult add(@RequestBody Systemdictionarytype systemdictionarytype) {
        System.out.println(systemdictionarytype);
        try {
            if (systemdictionarytype.getId() == null) {
                systemdictionarytypeservice.add(systemdictionarytype);
            } else {
                systemdictionarytypeservice.update(systemdictionarytype);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("操作失败").setSuccess(false);
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        try {
            systemdictionarytypeservice.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("操作失败").setSuccess(false);
        }
    }

    @PostMapping
    public PageList findQuery(@RequestBody SystemdictionarytypeQuery query) {
        System.out.println(query);
        return systemdictionarytypeservice.findQuery(query);
    }
}
